#include "Updatable.h"
#include "../../GameEngine.h"

Updatable::Updatable(int maxFrequency): maxFrequency(maxFrequency){
}

Updatable::~Updatable(){
}

void Updatable::update() {		
	unsigned long long timePassed = 1;						
	unsigned long long curTime = GetTickCount();							//We are interested in the milliseconds

	if(this->lastTime != 0)									//If we have recorded a last time...
		timePassed = curTime - this->lastTime;				//..we can compute the time that is passed

	//this->lastTime = curTime;								//Set last time to the current (for next call)

	if(timePassed > (unsigned long long)(1000.0 / (unsigned long long)maxFrequency)) {
		actualUpdate(timePassed);
		this->lastTime = curTime;
	}
}

void Updatable::setMaxFrequency(int frequency) {
	maxFrequency = frequency;
}